# -*- coding: utf-8 -*-
# @Author  : wyh
# @Time    : 2023/2/12 14:46
# @File    : shp查看
# @Email   : 2448979539@qq.com
import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'application.settings')
django.setup()
from django.contrib.gis.gdal import DataSource
from pathlib import Path
import world

world_shp = Path(world.__file__).resolve().parent / 'data' / 'TM_WORLD_BORDERS-0.3.shp'

ds = DataSource(world_shp)
print("shp_data", ds)
layer = ds[0]

print('layer', layer)  # 层
print('-' * 150)

print('layer.geom_type', layer.geom_type)  # polygon多边形
print('-' * 150)

print('layer.fields', layer.fields)
print('-' * 150)

print('layer.srs', layer.srs)
print('-' * 150)

print('遍历layer', len(layer))
for feat in layer:
    # feat.geom: 返回ogc标准的几何图形
    # type(feat) django.contlib.gis.gdal.feature.Feature
    print(feat.get('NAME'), feat.geom.num_points)